package com.hnkywl.sts.action.organ;

import com.hnkywl.sts.entity.organ.Khh;
import com.hnkywl.sts.service.organ.QykhhService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-5-27
 * Time: 下午8:36
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/organ/qykhh")
public class QykhhAction extends SimpleActionSupport {
    private QykhhService qykhhService;
    //开户行名称
    private String qykhhmc;
    //企业法人ID
    private Long qyfrId;
   //企业机构ID
    private  Long qyjgId;
    //开户行ID
    private Long qykhhId;
    //开户行
    private Khh qykhh;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;
    private String qyjgjc="";
    private String qc="";
    private String jc="";

    /**
     * 企业开户行列表展示
     */
    @Action("qykhhList")
    public void qykhhList() {
        this.renderJson(this.qykhhService.findQykhhList(qyjgId,qyjgjc,qc,jc,page, rows));
    }

    /**
     * 判断保存修改
     * @return
     */
    @Action("qykhh_content")
    public String khhContent() {
        if (qykhhId != null) {
            qykhh = qykhhService.findQyKhhById(qykhhId);
        } else {
            qykhh = new Khh();
            qykhh.setPxh(this.qykhhService.findNextPxh());
//            Qyjg qyjg   = new Qyjg();
//            qyjg.setId(qyjgId);
//            qykhh.setQyjg(qyjg);
        }
        return SUCCESS;
    }

    @Action("qyKhhmcList")
    public void khhmcList() {
        this.renderJson(this.qykhhService.findQyKhhmc(qyjgId, 0, -1));
    }

    /**
     * 保存企业开户行
     */
    @Action("save_qykhh")
    public void saveQykhh() {
        try {
            this.qykhhService.saveQyKhh(qykhh) ;
            renderText("{\"statusCode\":\"200\", \"message\":\"添加开户行成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 修改企业开户行
     */
    @Action("update_qykhh")
    public void updateQykhh() {
        try {
            this.qykhhService.updateQyKhh(qykhh) ;
            renderText("{\"statusCode\":\"200\",\"message\":\"修改开户行成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     deleteQyKhh
     * 功能描述:   删除企业开户行
     */
    @Action("delete_qykhh")
    public void deleteQyKhh() {
        try {
            this.qykhhService.deleteQyKhh(qykhhId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除开户行成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void ajaxValidate() {
        if (!qykhhService.ajaxValidate(qykhhId,validateVal,validateField))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }

    //根据当前的公司机构获得下一个排序号
    @Action("get_nextpxh")
    public void getNextPxh() {
        renderText(qykhhService.findNextPxh(qyjgId).toString());
    }

    //========getter=============setter==========================

    public String getJc() {
        return jc;
    }

    public void setJc(String jc) {
        this.jc = jc;
    }

    public String getQyjgjc() {
        return qyjgjc;
    }

    public void setQyjgjc(String qyjgjc) {
        this.qyjgjc = qyjgjc;
    }

    public String getQc() {
        return qc;
    }

    public void setQc(String qc) {
        this.qc = qc;
    }

    public String getQykhhmc() {
        return qykhhmc;
    }

    public void setQykhhmc(String qykhhmc) {
        this.qykhhmc = qykhhmc;
    }

    public Long getQykhhId() {
        return qykhhId;
    }

    public void setQykhhId(Long qykhhId) {
        this.qykhhId = qykhhId;
    }

    public Khh getQykhh() {
        return qykhh;
    }

    public void setQykhh(Khh qykhh) {
        this.qykhh = qykhh;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public Long getQyjgId() {
        return qyjgId;
    }

    public void setQyjgId(Long qyjgId) {
        this.qyjgId = qyjgId;
    }

    @Autowired
    public void setQykhhService(QykhhService qykhhService) {
        this.qykhhService = qykhhService;
    }
}
